package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.PmsPurchaseSku;
import com.ruoyi.system.service.IPmsPurchaseSkuService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购详情Controller
 *
 * @author ruoyi
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/sku")
@CrossOrigin
public class PmsPurchaseSkuController extends BaseController
{
    @Autowired
    private IPmsPurchaseSkuService pmsPurchaseSkuService;

    /**
     * 查询采购详情列表
     */
    @RequiresPermissions("system:sku:list")
    @GetMapping("/list")
    public TableDataInfo list(PmsPurchaseSku pmsPurchaseSku)
    {
        startPage();
        List<PmsPurchaseSku> list = pmsPurchaseSkuService.selectPmsPurchaseSkuList(pmsPurchaseSku);
        return getDataTable(list);
    }

    /**
     * 导出采购详情列表
     */
    @RequiresPermissions("system:sku:export")
    @Log(title = "采购详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsPurchaseSku pmsPurchaseSku)
    {
        List<PmsPurchaseSku> list = pmsPurchaseSkuService.selectPmsPurchaseSkuList(pmsPurchaseSku);
        ExcelUtil<PmsPurchaseSku> util = new ExcelUtil<PmsPurchaseSku>(PmsPurchaseSku.class);
        util.exportExcel(response, list, "采购详情数据");
    }

    /**
     * 获取采购详情详细信息
     */
    @RequiresPermissions("system:sku:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pmsPurchaseSkuService.selectPmsPurchaseSkuById(id));
    }

    /**
     * 新增采购详情
     */
    @RequiresPermissions("system:sku:add")
    @Log(title = "采购详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsPurchaseSku pmsPurchaseSku)
    {
        return toAjax(pmsPurchaseSkuService.insertPmsPurchaseSku(pmsPurchaseSku));
    }

    /**
     * 修改采购详情
     */
    @RequiresPermissions("system:sku:edit")
    @Log(title = "采购详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsPurchaseSku pmsPurchaseSku)
    {
        return toAjax(pmsPurchaseSkuService.updatePmsPurchaseSku(pmsPurchaseSku));
    }

    /**
     * 删除采购详情
     */
    @RequiresPermissions("system:sku:remove")
    @Log(title = "采购详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsPurchaseSkuService.deletePmsPurchaseSkuByIds(ids));
    }
}
